<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="custom" tagdir="/WEB-INF/tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Konto użytkownika</title>
	<link href='/css/quickAccess.css' rel='stylesheet' type='text/css' />
	<script type="text/javascript" src="/scripts/quickAccess.js"></script>
	<script type="text/javascript">
		function save() {
			$('span[id^="error_"]').html('');
			$("#userForm").spin();
			$.ajax({
				type : "POST",
				url : '/user/update',
				data : $("#userForm").serialize(),
				success : function(response) {
					$("#userForm").spin(false);
					if (response.status == "FAILURE") {
						for (i = 0; i < response.errorMessageList.length; i++) {
							var item = response.errorMessageList[i];
							$("#userForm"+" span[id='error_" + response.errorMessageList[i].fieldName+"']").html(
									response.errorMessageList[i].message);
						}
						$.gritter.add({
							title: response.result.title,
							text: response.result.content
						});
					}
					else {
						$.gritter.add({
							title: response.result.title,
							text: response.result.content
						});
					}
				},
				error : function(e) {
					alert(e);
				}
			});
		}
	</script>
</head>
<body>
	<div id="content">
	<h3>${userForm.user.username }</h3>
		<br />
		<form:form method="POST"  commandName="userForm" >
			<custom:inputText label="Imię" name="user.name"/>
			<custom:inputText label="Nazwisko" name="user.surname"/>
			<custom:inputText label="Login" name="user.username"/>
			<custom:inputPassword label="Hasło" name="user.password"/>
			<custom:inputPassword label="Powtórz hasło" name="password2"/>
			<custom:button onclick="save()" value="Zapisz"/>
		</form:form>
	</div>
	<div id="sidePanel">
		<jsp:include page="accountMenu.jsp"/>
	</div>
</body>
</html>